'use strict';

var clientApp = angular.module('clientApp', [
        'ngRoute', 'ngCookies', 'ngResource', 'ngSanitize', 'ngAnimate',
        'clientUtils', 'commonModels', 'clientDirectives', 'clientServices', 'clientControllers'
  ])
  .config(['$routeProvider', '$provide', '$httpProvider',
        function ($routeProvider, $provide, $httpProvider) {
    $routeProvider
        .when('/:appId/:subId', {
            templateUrl: '/client/views/index.html'
            //controller: 'AppCtrl'
        })
//        .otherwise({
//            redirectTo: '/'
//        });

        $provide.factory('myHttpInterceptor', ['Constant', '$q', function(Constant, $q) {
            return {
                'request': function(config) {
                    if (config.params) {
                        config.params.pageSize = Constant.PAGE_SIZE;
                    }
                    return config || $q.when(config);
                },
                'requestError': function(rejection) {
//                    if (canRecover(rejection)) {
//                        return responseOrNewPromise
//                    }
                    return $q.reject(rejection);
                },
                'response': function(response) {
                    return response || $q.when(response);
                },
                'responseError': function(rejection) {
//                    if (canRecover(rejection)) {
//                        return responseOrNewPromise
//                    }
                    return $q.reject(rejection);
                }
            };
        }]);

        $httpProvider.interceptors.push('myHttpInterceptor');
  }]);